package com.lagou.controlller;

import com.lagou.pojo.Article;
import com.lagou.reponsitory.ArticleReponsitory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@Controller
public class ArticleController {

    @Autowired
    private ArticleReponsitory articleReponsitory;

    @RequestMapping("/index")
    public String index(Model model, @RequestParam(value = "page", defaultValue = "0")int page, @RequestParam(value = "size", defaultValue = "2")int size){
        //共享文章信息
        Pageable pageable= PageRequest.of(page,size);
        Page<Article> articleList = articleReponsitory.findAll(pageable);
        model.addAttribute("articles",articleList);
        return "client/index";
    }

}
